<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Log;

class WechatController extends Controller
{
    /**
     * 处理微信的请求消息
     *
     * @return string
     */
    public function serve()
    {
        Log::info('request arrived.'); # 注意：Log 为 Laravel 组件，所以它记的日志去 Laravel 日志看，而不是 EasyWeChat 日志

        $app = app('wechat.official_account');
        //dd($app);
        $app->server->push(function($message){
            return "欢迎关注!";
        });

        return $app->server->serve();
    }

    public function createMenu()
    {
        $app = app('wechat.official_account');
        $buttons = [
            [
                "type" => "view",
                "name" => "系统介绍",
                "url"  => "http://u2696103.viewer.maka.im/k/C41MRPZC?from=singlemessage&isappinstalled=0"
            ],
            [
                "name"       => "订场助手",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "在线预定",
                        "url"  => "https://chczs.toupiao110.cn/user/task/create"
                    ],
                    [
                        "type" => "view",
                        "name" => "我的订单",
                        "url"  => "https://chczs.toupiao110.cn/user/task/"
                    ],
                ],
            ],
            [
                "name"       => "工单系统",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "提交工单",
                        "url"  => "http://tds.qdss.com.cn/user/task/create"
                    ],
                    [
                        "type" => "view",
                        "name" => "我的工单",
                        "url"  => "http://tds.qdss.com.cn/user/task/"
                    ],
                ],
            ],        
            
           
        ];
        $rs = $app->menu->create($buttons);
        if($rs['errcode']==0) {
            return response()->json(['status'=>'success','msg'=>'操作成功']);
        } 
        return response()->json(['status'=>'danger','msg'=>$rs['errmsg']]);
    }
    
}
